package algorithm.sort;

/**
 * @Author: 李浩然
 * @Date: 2020/12/28 12:54 下午
 */
public class quickSort {

    public static void quickSort(int[] num, int left, int right) {
        if (num == null || num.length == 0) return;
        if (left >= right) return;
        int i = left, j = right, temp = num[i];
        while (i < j) {
            while (i < j && num[j] >= temp) {
                j--;
            }
            num[i] = num[j];
            while (i < j && num[i] <= temp) {
                i++;
            }
            num[j] = num[i];
            num[i] = temp;
            quickSort(num, left, i - 1);
            quickSort(num, i + 1, right);
        }
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 5, 4, 2};
        quickSort(arr, 0, arr.length - 1);
        for (int a : arr) {
            System.out.println(a);
        }
    }

}
